package com.hu.zhcc.shiro.controller.xsx;


import com.hu.zhcc.shiro.entity.xsx.XsxTGozuoToji;
import com.hu.zhcc.shiro.entity.xsx.XsxTInterposeFollowupVisit;
import com.hu.zhcc.shiro.service.xsx.TGozuoTojiService;
import com.hu.zhcc.shiro.service.xsx.TInterposeFollowupVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 随访日记表 前端控制器
 * </p>
 *
 * @author xsx
 * @since 2021-06-23
 */
@RestController
@RequestMapping("/tInterposeFollowupVisit")
public class TInterposeFollowupVisitController {
    @Autowired
    TInterposeFollowupVisitService tInterposeFollowupVisitService;
    @Autowired
    TGozuoTojiService tGozuoTojiService;

    @PutMapping("/{jksid}")
    private List<XsxTInterposeFollowupVisit> yd(@PathVariable("jksid") Integer jksid){
        return tInterposeFollowupVisitService.queryAll(jksid);
    }

    @PostMapping("/{str}")
    private XsxTInterposeFollowupVisit queryByFileNum(@PathVariable("str") String str){
        return tInterposeFollowupVisitService.queryVisitByFileNum(str);
    }

    @PutMapping("")
    public int upd(@RequestBody XsxTInterposeFollowupVisit hf){
        XsxTGozuoToji tGozuoToji = tGozuoTojiService.queryByJks(hf.getHealthMgrId());
        System.out.println(tGozuoToji);
        System.out.println(hf.getHealthMgrId());
        if(tGozuoToji==null){
            XsxTGozuoToji t=new XsxTGozuoToji();
            t.setJks(hf.getHealthMgrId());
            t.setGyfanNum(0);
            t.setGyhfNum(1);
            t.setGyjsNum(0);
            tGozuoTojiService.addOne(t);
        }
        if(tGozuoToji!=null){
            XsxTGozuoToji t=new XsxTGozuoToji();
            t.setJks(hf.getHealthMgrId());
            t.setGyfanNum(tGozuoToji.getGyfanNum());
            t.setGyhfNum(tGozuoToji.getGyhfNum()+1);
            t.setGyjsNum(tGozuoToji.getGyjsNum());
            tGozuoTojiService.updateNum(t);
        }
        return tInterposeFollowupVisitService.updateVisit(hf);
    }

    @PutMapping("/{id}/{jks}")
    private int jsgy(@PathVariable("id") Integer id,@PathVariable("jks")Integer jks){
        System.out.println(jks);
        System.out.println(id);
        XsxTGozuoToji tGozuoToji = tGozuoTojiService.queryByJks(jks);
        if(tGozuoToji==null){
            XsxTGozuoToji t=new XsxTGozuoToji();
            t.setJks(jks);
            t.setGyfanNum(0);
            t.setGyhfNum(0);
            t.setGyjsNum(1);
            tGozuoTojiService.addOne(t);
        }
        if(tGozuoToji!=null){
            XsxTGozuoToji t=new XsxTGozuoToji();
            t.setJks(jks);
            t.setGyfanNum(tGozuoToji.getGyfanNum());
            t.setGyhfNum(tGozuoToji.getGyhfNum());
            t.setGyjsNum(tGozuoToji.getGyjsNum()+1);
            tGozuoTojiService.updateNum(t);
        }
        return tInterposeFollowupVisitService.jsgy(id);
    }

}

